package com.why.rpc.core.common.message;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import com.why.rpc.core.common.enums.ResponseData;

import java.io.Serializable;

/**
 * @program: why-rpc-framework
 * @description:
 * @author: @why
 * @create: 2021-03-15 15:27
 **/
@Data
@Getter
@Builder
@AllArgsConstructor

public class RpcResponse implements Serializable {

    /**
     * 响应状态码
     */
    private Integer responseCode;

    /**
     * 响应数据
     */
    private Object data;

    /**
     * 响应信息
     */
    private String message;
    private RpcResponse() {

    }

    /**
     * 响应成功
     * @param data
     * @return
     */
    public static RpcResponse isSuccess(Object data){
        RpcResponse response = new RpcResponse();
        response.setData(data);
        response.setMessage(ResponseData.RESPONSE_SUCCESS.getMessage());
        response.setResponseCode(ResponseData.RESPONSE_SUCCESS.getCode());
        return response;
    }
    /**
     * 响应失败
     * @param errorMessage
     * @return
     */
    public static RpcResponse isError(String errorMessage){
        RpcResponse response = new RpcResponse();
        response.setData(errorMessage);
        response.setMessage(ResponseData.RESPONSE_ERROR.getMessage());
        response.setResponseCode(ResponseData.RESPONSE_ERROR.getCode());
        return response;
    }


}